(function($) {
	$.fn.joinCheckboxs = function(options) {
		options = $.extend({
					closestTagName : 'tr',
					closestTagCssName : 'success'
				}, options);

		if (options.selector == undefined) {
			return this;
		}

		$(options.selector).on('click', {
					main : $(this),
					options : options
				}, function(event) {
					var $this = $(this);

					var mainChecked = $this.is(':checked');

					var checkedSize = $(event.data.options.selector).filter(':checked').size();

					var subCheckboxs = $(event.data.options.selector).size();

					if (mainChecked) {
						event.data.main.prop({
									'checked' : (subCheckboxs == checkedSize)
								});

						if ((event.data.options.closestTagCssName != undefined) && (event.data.options.closestTagCssName != '')) {
							$this.closest(event.data.options.closestTagName).addClass(event.data.options.closestTagCssName);
						}
					} else {
						event.data.main.prop({
									'checked' : false
								});

						if ((event.data.options.closestTagCssName != undefined) && (event.data.options.closestTagCssName != '')) {
							$this.closest(event.data.options.closestTagName).removeClass(event.data.options.closestTagCssName);
						}
					}
				});

		return this.on('click', {
					options : options
				}, function(event) {
					var $this = $(this);

					var checked = $this.is(':checked');

					if (checked) {
						$(event.data.options.selector).not(':checked').each(function() {
									var $this = $(this);

									$this.prop({
												'checked' : true
											});

									if ((event.data.options.closestTagCssName != undefined) && (event.data.options.closestTagCssName != '')) {
										$this.closest(event.data.options.closestTagName).addClass(event.data.options.closestTagCssName);
									}
								});
					} else {
						$(event.data.options.selector).filter(':checked').each(function() {
									var $this = $(this);

									$this.prop({
												'checked' : false
											});

									if ((event.data.options.closestTagCssName != undefined) && (event.data.options.closestTagCssName != '')) {
										$this.closest(event.data.options.closestTagName).removeClass(event.data.options.closestTagCssName);
									}
								});
					}
				});
	};

	$.fn.DataProp = function() {
		return this.each(function() {
					var $this = $(this);

					var isValue = $this.is('[data-value]');

					if (isValue) {
						var dataValue = $this.attr('data-value');

						$this.val(dataValue);
					}

					var isDataProp = $this.is('[data-prop]');

					if (isDataProp) {
						var propText = $this.attr('data-prop');

						if ((propText != undefined) && (propText == '')) {
							return;
						}

						propText = "{" + $.trim(propText) + "}";

						try {
							var propMap = $.parseJSON(propText);

							$this.prop(propMap);
						} catch (e) {
						}
					}
				});
	};
})(jQuery);
